<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The sitemap framework &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../index.html" />
    <link rel="up" title="contrib packages" href="index.html" />
    <link rel="next" title="The “sites” framework" href="sites.html" />
    <link rel="prev" title="The redirects app" href="redirects.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="redirects.html" title="The redirects app">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="sites.html" title="The &amp;#8220;sites&amp;#8221; framework">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-sitemaps">
            
  <div class="section" id="s-module-django.contrib.sitemaps">
<span id="s-the-sitemap-framework"></span><span id="module-django.contrib.sitemaps"></span><span id="the-sitemap-framework"></span><h1>The sitemap framework<a class="headerlink" href="#module-django.contrib.sitemaps" title="Permalink to this headline">¶</a></h1>
<p>Django comes with a high-level sitemap-generating framework that makes
creating <a class="reference external" href="http://www.sitemaps.org/">sitemap</a> XML files easy.</p>
<div class="section" id="s-overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>A sitemap is an XML file on your Web site that tells search-engine indexers how
frequently your pages change and how &#8220;important&#8221; certain pages are in relation
to other pages on your site. This information helps search engines index your
site.</p>
<p>The Django sitemap framework automates the creation of this XML file by letting
you express this information in Python code.</p>
<p>It works much like Django&#8217;s <a class="reference internal" href="syndication.html"><em>syndication framework</em></a>. To create a sitemap, just write a
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> class and point to it in your
<a class="reference internal" href="../../topics/http/urls.html"><em>URLconf</em></a>.</p>
</div>
<div class="section" id="s-installation">
<span id="installation"></span><h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<p>To install the sitemap app, follow these steps:</p>
<ol class="arabic simple">
<li>Add <tt class="docutils literal"><span class="pre">'django.contrib.sitemaps'</span></tt> to your <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a>
setting.</li>
<li>Make sure <tt class="docutils literal"><span class="pre">'django.template.loaders.app_directories.Loader'</span></tt>
is in your <a class="reference internal" href="../settings.html#std:setting-TEMPLATE_LOADERS"><tt class="xref std std-setting docutils literal"><span class="pre">TEMPLATE_LOADERS</span></tt></a> setting. It&#8217;s in there by default,
so you&#8217;ll only need to change this if you&#8217;ve changed that setting.</li>
<li>Make sure you&#8217;ve installed the
<a class="reference internal" href="sites.html#module-django.contrib.sites" title="django.contrib.sites: Lets you operate multiple Web sites from the same database and Django project"><tt class="xref py py-mod docutils literal"><span class="pre">sites</span> <span class="pre">framework</span></tt></a>.</li>
</ol>
<p>(Note: The sitemap application doesn&#8217;t install any database tables. The only
reason it needs to go into <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> is so that the
<a class="reference internal" href="../templates/api.html#django.template.loaders.app_directories.Loader" title="django.template.loaders.app_directories.Loader"><tt class="xref py py-func docutils literal"><span class="pre">Loader()</span></tt></a> template
loader can find the default templates.)</p>
</div>
<div class="section" id="s-initialization">
<span id="initialization"></span><h2>Initialization<a class="headerlink" href="#initialization" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="django.contrib.sitemaps.views.sitemap">
<tt class="descclassname">views.</tt><tt class="descname">sitemap</tt>(<em>request</em>, <em>sitemaps</em>, <em>section=None</em>, <em>template_name='sitemap.xml'</em>, <em>content_type='application/xml'</em>)<a class="headerlink" href="#django.contrib.sitemaps.views.sitemap" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>To activate sitemap generation on your Django site, add this line to your
<a class="reference internal" href="../../topics/http/urls.html"><em>URLconf</em></a>:</p>
<div class="highlight-python"><div class="highlight"><pre>from django.contrib.sitemaps.views import sitemap

(r&#39;^sitemap\.xml$&#39;, sitemap, {&#39;sitemaps&#39;: sitemaps},
    name=&#39;django.contrib.sitemaps.views.sitemap&#39;)
</pre></div>
</div>
<p>This tells Django to build a sitemap when a client accesses <tt class="file docutils literal"><span class="pre">/sitemap.xml</span></tt>.</p>
<p>The name of the sitemap file is not important, but the location is. Search
engines will only index links in your sitemap for the current URL level and
below. For instance, if <tt class="file docutils literal"><span class="pre">sitemap.xml</span></tt> lives in your root directory, it may
reference any URL in your site. However, if your sitemap lives at
<tt class="file docutils literal"><span class="pre">/content/sitemap.xml</span></tt>, it may only reference URLs that begin with
<tt class="file docutils literal"><span class="pre">/content/</span></tt>.</p>
<p>The sitemap view takes an extra, required argument: <tt class="docutils literal"><span class="pre">{'sitemaps':</span> <span class="pre">sitemaps}</span></tt>.
<tt class="docutils literal"><span class="pre">sitemaps</span></tt> should be a dictionary that maps a short section label (e.g.,
<tt class="docutils literal"><span class="pre">blog</span></tt> or <tt class="docutils literal"><span class="pre">news</span></tt>) to its <a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> class
(e.g., <tt class="docutils literal"><span class="pre">BlogSitemap</span></tt> or <tt class="docutils literal"><span class="pre">NewsSitemap</span></tt>). It may also map to an <em>instance</em> of
a <a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> class (e.g.,
<tt class="docutils literal"><span class="pre">BlogSitemap(some_var)</span></tt>).</p>
</div>
<div class="section" id="s-sitemap-classes">
<span id="sitemap-classes"></span><h2>Sitemap classes<a class="headerlink" href="#sitemap-classes" title="Permalink to this headline">¶</a></h2>
<p>A <a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> class is a simple Python
class that represents a &#8220;section&#8221; of entries in your sitemap. For example,
one <a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> class could represent
all the entries of your Weblog, while another could represent all of the
events in your events calendar.</p>
<p>In the simplest case, all these sections get lumped together into one
<tt class="file docutils literal"><span class="pre">sitemap.xml</span></tt>, but it&#8217;s also possible to use the framework to generate a
sitemap index that references individual sitemap files, one per section. (See
<a class="reference internal" href="#creating-a-sitemap-index">Creating a sitemap index</a> below.)</p>
<p><a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> classes must subclass
<tt class="docutils literal"><span class="pre">django.contrib.sitemaps.Sitemap</span></tt>. They can live anywhere in your codebase.</p>
</div>
<div class="section" id="s-a-simple-example">
<span id="a-simple-example"></span><h2>A simple example<a class="headerlink" href="#a-simple-example" title="Permalink to this headline">¶</a></h2>
<p>Let&#8217;s assume you have a blog system, with an <tt class="docutils literal"><span class="pre">Entry</span></tt> model, and you want your
sitemap to include all the links to your individual blog entries. Here&#8217;s how
your sitemap class might look:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.sitemaps</span> <span class="kn">import</span> <span class="n">Sitemap</span>
<span class="kn">from</span> <span class="nn">blog.models</span> <span class="kn">import</span> <span class="n">Entry</span>

<span class="k">class</span> <span class="nc">BlogSitemap</span><span class="p">(</span><span class="n">Sitemap</span><span class="p">):</span>
    <span class="n">changefreq</span> <span class="o">=</span> <span class="s">&quot;never&quot;</span>
    <span class="n">priority</span> <span class="o">=</span> <span class="mf">0.5</span>

    <span class="k">def</span> <span class="nf">items</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">Entry</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">is_draft</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">lastmod</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">obj</span><span class="o">.</span><span class="n">pub_date</span>
</pre></div>
</div>
<p>Note:</p>
<ul class="simple">
<li><a class="reference internal" href="#django.contrib.sitemaps.Sitemap.changefreq" title="django.contrib.sitemaps.Sitemap.changefreq"><tt class="xref py py-attr docutils literal"><span class="pre">changefreq</span></tt></a> and <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.priority" title="django.contrib.sitemaps.Sitemap.priority"><tt class="xref py py-attr docutils literal"><span class="pre">priority</span></tt></a> are class
attributes corresponding to <tt class="docutils literal"><span class="pre">&lt;changefreq&gt;</span></tt> and <tt class="docutils literal"><span class="pre">&lt;priority&gt;</span></tt> elements,
respectively. They can be made callable as functions, as
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod</span></tt></a> was in the example.</li>
<li><a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a> is simply a method that returns a list of
objects. The objects returned will get passed to any callable methods
corresponding to a sitemap property (<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.location" title="django.contrib.sitemaps.Sitemap.location"><tt class="xref py py-attr docutils literal"><span class="pre">location</span></tt></a>,
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod</span></tt></a>, <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.changefreq" title="django.contrib.sitemaps.Sitemap.changefreq"><tt class="xref py py-attr docutils literal"><span class="pre">changefreq</span></tt></a>, and
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.priority" title="django.contrib.sitemaps.Sitemap.priority"><tt class="xref py py-attr docutils literal"><span class="pre">priority</span></tt></a>).</li>
<li><a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod</span></tt></a> should return a Python <tt class="docutils literal"><span class="pre">datetime</span></tt> object.</li>
<li>There is no <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.location" title="django.contrib.sitemaps.Sitemap.location"><tt class="xref py py-attr docutils literal"><span class="pre">location</span></tt></a> method in this example, but you
can provide it in order to specify the URL for your object. By default,
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.location" title="django.contrib.sitemaps.Sitemap.location"><tt class="xref py py-attr docutils literal"><span class="pre">location()</span></tt></a> calls <tt class="docutils literal"><span class="pre">get_absolute_url()</span></tt> on each object
and returns the result.</li>
</ul>
</div>
<div class="section" id="s-sitemap-class-reference">
<span id="sitemap-class-reference"></span><h2>Sitemap class reference<a class="headerlink" href="#sitemap-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.sitemaps.Sitemap">
<em class="property">class </em><tt class="descname">Sitemap</tt><a class="reference internal" href="../../_modules/django/contrib/sitemaps.html#Sitemap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.sitemaps.Sitemap" title="Permalink to this definition">¶</a></dt>
<dd><p>A <tt class="docutils literal"><span class="pre">Sitemap</span></tt> class can define the following methods/attributes:</p>
<dl class="attribute">
<dt id="django.contrib.sitemaps.Sitemap.items">
<tt class="descname">items</tt><a class="reference internal" href="../../_modules/django/contrib/sitemaps.html#Sitemap.items"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.sitemaps.Sitemap.items" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>Required.</strong> A method that returns a list of objects. The framework
doesn&#8217;t care what <em>type</em> of objects they are; all that matters is that
these objects get passed to the <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.location" title="django.contrib.sitemaps.Sitemap.location"><tt class="xref py py-attr docutils literal"><span class="pre">location()</span></tt></a>,
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod()</span></tt></a>, <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.changefreq" title="django.contrib.sitemaps.Sitemap.changefreq"><tt class="xref py py-attr docutils literal"><span class="pre">changefreq()</span></tt></a> and
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.priority" title="django.contrib.sitemaps.Sitemap.priority"><tt class="xref py py-attr docutils literal"><span class="pre">priority()</span></tt></a> methods.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.sitemaps.Sitemap.location">
<tt class="descname">location</tt><a class="reference internal" href="../../_modules/django/contrib/sitemaps.html#Sitemap.location"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.sitemaps.Sitemap.location" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>Optional.</strong> Either a method or attribute.</p>
<p>If it&#8217;s a method, it should return the absolute path for a given object
as returned by <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a>.</p>
<p>If it&#8217;s an attribute, its value should be a string representing an
absolute path to use for <em>every</em> object returned by
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a>.</p>
<p>In both cases, &#8220;absolute path&#8221; means a URL that doesn&#8217;t include the
protocol or domain. Examples:</p>
<ul class="simple">
<li>Good: <tt class="file docutils literal"><span class="pre">'/foo/bar/'</span></tt></li>
<li>Bad: <tt class="file docutils literal"><span class="pre">'example.com/foo/bar/'</span></tt></li>
<li>Bad: <tt class="file docutils literal"><span class="pre">'http://example.com/foo/bar/'</span></tt></li>
</ul>
<p>If <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.location" title="django.contrib.sitemaps.Sitemap.location"><tt class="xref py py-attr docutils literal"><span class="pre">location</span></tt></a> isn&#8217;t provided, the framework will call
the <tt class="docutils literal"><span class="pre">get_absolute_url()</span></tt> method on each object as returned by
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a>.</p>
<p>To specify a protocol other than <tt class="docutils literal"><span class="pre">'http'</span></tt>, use
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.protocol" title="django.contrib.sitemaps.Sitemap.protocol"><tt class="xref py py-attr docutils literal"><span class="pre">protocol</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.sitemaps.Sitemap.lastmod">
<tt class="descname">lastmod</tt><a class="headerlink" href="#django.contrib.sitemaps.Sitemap.lastmod" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>Optional.</strong> Either a method or attribute.</p>
<p>If it&#8217;s a method, it should take one argument &#8211; an object as returned by
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a> &#8211; and return that object&#8217;s last-modified date/time, as a Python
<tt class="docutils literal"><span class="pre">datetime.datetime</span></tt> object.</p>
<p>If it&#8217;s an attribute, its value should be a Python <tt class="docutils literal"><span class="pre">datetime.datetime</span></tt> object
representing the last-modified date/time for <em>every</em> object returned by
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a>.</p>
<div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>If all items in a sitemap have a <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod</span></tt></a>, the sitemap
generated by <a class="reference internal" href="#django.contrib.sitemaps.views.sitemap" title="django.contrib.sitemaps.views.sitemap"><tt class="xref py py-func docutils literal"><span class="pre">views.sitemap()</span></tt></a> will have a <tt class="docutils literal"><span class="pre">Last-Modified</span></tt>
header equal to the latest <tt class="docutils literal"><span class="pre">lastmod</span></tt>. You can activate the
<a class="reference internal" href="../middleware.html#django.middleware.http.ConditionalGetMiddleware" title="django.middleware.http.ConditionalGetMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">ConditionalGetMiddleware</span></tt></a> to make
Django respond appropriately to requests with an <tt class="docutils literal"><span class="pre">If-Modified-Since</span></tt>
header which will prevent sending the sitemap if it hasn&#8217;t changed.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.sitemaps.Sitemap.changefreq">
<tt class="descname">changefreq</tt><a class="headerlink" href="#django.contrib.sitemaps.Sitemap.changefreq" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>Optional.</strong> Either a method or attribute.</p>
<p>If it&#8217;s a method, it should take one argument &#8211; an object as returned by
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a> &#8211; and return that object&#8217;s change frequency, as a Python string.</p>
<p>If it&#8217;s an attribute, its value should be a string representing the change
frequency of <em>every</em> object returned by <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a>.</p>
<p>Possible values for <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.changefreq" title="django.contrib.sitemaps.Sitemap.changefreq"><tt class="xref py py-attr docutils literal"><span class="pre">changefreq</span></tt></a>, whether you use a method or attribute, are:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">'always'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'hourly'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'daily'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'weekly'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'monthly'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'yearly'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'never'</span></tt></li>
</ul>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.sitemaps.Sitemap.priority">
<tt class="descname">priority</tt><a class="headerlink" href="#django.contrib.sitemaps.Sitemap.priority" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>Optional.</strong> Either a method or attribute.</p>
<p>If it&#8217;s a method, it should take one argument &#8211; an object as returned by
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a> &#8211; and return that object&#8217;s priority, as either a string or float.</p>
<p>If it&#8217;s an attribute, its value should be either a string or float representing
the priority of <em>every</em> object returned by <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a>.</p>
<p>Example values for <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.priority" title="django.contrib.sitemaps.Sitemap.priority"><tt class="xref py py-attr docutils literal"><span class="pre">priority</span></tt></a>: <tt class="docutils literal"><span class="pre">0.4</span></tt>, <tt class="docutils literal"><span class="pre">1.0</span></tt>. The default priority of a
page is <tt class="docutils literal"><span class="pre">0.5</span></tt>. See the <a class="reference external" href="http://www.sitemaps.org/protocol.html#prioritydef">sitemaps.org documentation</a> for more.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.sitemaps.Sitemap.protocol">
<tt class="descname">protocol</tt><a class="headerlink" href="#django.contrib.sitemaps.Sitemap.protocol" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>Optional.</strong></p>
<p>This attribute defines the protocol (<tt class="docutils literal"><span class="pre">'http'</span></tt> or <tt class="docutils literal"><span class="pre">'https'</span></tt>) of the
URLs in the sitemap. If it isn&#8217;t set, the protocol with which the
sitemap was requested is used. If the sitemap is built outside the
context of a request, the default is <tt class="docutils literal"><span class="pre">'http'</span></tt>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-shortcuts">
<span id="shortcuts"></span><h2>Shortcuts<a class="headerlink" href="#shortcuts" title="Permalink to this headline">¶</a></h2>
<p>The sitemap framework provides a couple convenience classes for common cases:</p>
<dl class="class">
<dt id="django.contrib.sitemaps.FlatPageSitemap">
<em class="property">class </em><tt class="descname">FlatPageSitemap</tt><a class="reference internal" href="../../_modules/django/contrib/sitemaps.html#FlatPageSitemap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.sitemaps.FlatPageSitemap" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="#django.contrib.sitemaps.FlatPageSitemap" title="django.contrib.sitemaps.FlatPageSitemap"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.sitemaps.FlatPageSitemap</span></tt></a> class looks at all
publicly visible <a class="reference internal" href="flatpages.html#module-django.contrib.flatpages" title="django.contrib.flatpages: A framework for managing simple ?flat? HTML content in a database."><tt class="xref py py-mod docutils literal"><span class="pre">flatpages</span></tt></a>
defined for the current <a class="reference internal" href="../settings.html#std:setting-SITE_ID"><tt class="xref std std-setting docutils literal"><span class="pre">SITE_ID</span></tt></a> (see the
<a class="reference internal" href="sites.html#module-django.contrib.sites" title="django.contrib.sites: Lets you operate multiple Web sites from the same database and Django project"><tt class="xref py py-mod docutils literal"><span class="pre">sites</span> <span class="pre">documentation</span></tt></a>) and
creates an entry in the sitemap. These entries include only the
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.location" title="django.contrib.sitemaps.Sitemap.location"><tt class="xref py py-attr docutils literal"><span class="pre">location</span></tt></a> attribute &#8211; not <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod</span></tt></a>,
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.changefreq" title="django.contrib.sitemaps.Sitemap.changefreq"><tt class="xref py py-attr docutils literal"><span class="pre">changefreq</span></tt></a> or <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.priority" title="django.contrib.sitemaps.Sitemap.priority"><tt class="xref py py-attr docutils literal"><span class="pre">priority</span></tt></a>.</p>
</dd></dl>

<dl class="class">
<dt id="django.contrib.sitemaps.GenericSitemap">
<em class="property">class </em><tt class="descname">GenericSitemap</tt><a class="reference internal" href="../../_modules/django/contrib/sitemaps.html#GenericSitemap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.sitemaps.GenericSitemap" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="#django.contrib.sitemaps.GenericSitemap" title="django.contrib.sitemaps.GenericSitemap"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.sitemaps.GenericSitemap</span></tt></a> class allows you to
create a sitemap by passing it a dictionary which has to contain at least
a <tt class="docutils literal"><span class="pre">queryset</span></tt> entry. This queryset will be used to generate the items
of the sitemap. It may also have a <tt class="docutils literal"><span class="pre">date_field</span></tt> entry that
specifies a date field for objects retrieved from the <tt class="docutils literal"><span class="pre">queryset</span></tt>.
This will be used for the <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.lastmod" title="django.contrib.sitemaps.Sitemap.lastmod"><tt class="xref py py-attr docutils literal"><span class="pre">lastmod</span></tt></a> attribute in the
generated sitemap. You may also pass <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.priority" title="django.contrib.sitemaps.Sitemap.priority"><tt class="xref py py-attr docutils literal"><span class="pre">priority</span></tt></a> and
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap.changefreq" title="django.contrib.sitemaps.Sitemap.changefreq"><tt class="xref py py-attr docutils literal"><span class="pre">changefreq</span></tt></a> keyword arguments to the
<a class="reference internal" href="#django.contrib.sitemaps.GenericSitemap" title="django.contrib.sitemaps.GenericSitemap"><tt class="xref py py-class docutils literal"><span class="pre">GenericSitemap</span></tt></a>  constructor to specify
these attributes for all URLs.</p>
</dd></dl>

<div class="section" id="s-example">
<span id="example"></span><h3>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h3>
<p>Here&#8217;s an example of a <a class="reference internal" href="../../topics/http/urls.html"><em>URLconf</em></a> using both:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span>
<span class="kn">from</span> <span class="nn">django.contrib.sitemaps</span> <span class="kn">import</span> <span class="n">FlatPageSitemap</span><span class="p">,</span> <span class="n">GenericSitemap</span>
<span class="kn">from</span> <span class="nn">django.contrib.sitemaps.views</span> <span class="kn">import</span> <span class="n">sitemap</span>
<span class="kn">from</span> <span class="nn">blog.models</span> <span class="kn">import</span> <span class="n">Entry</span>

<span class="n">info_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;queryset&#39;</span><span class="p">:</span> <span class="n">Entry</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">(),</span>
    <span class="s">&#39;date_field&#39;</span><span class="p">:</span> <span class="s">&#39;pub_date&#39;</span><span class="p">,</span>
<span class="p">}</span>

<span class="n">sitemaps</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;flatpages&#39;</span><span class="p">:</span> <span class="n">FlatPageSitemap</span><span class="p">,</span>
    <span class="s">&#39;blog&#39;</span><span class="p">:</span> <span class="n">GenericSitemap</span><span class="p">(</span><span class="n">info_dict</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mf">0.6</span><span class="p">),</span>
<span class="p">}</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="c"># some generic view using info_dict</span>
    <span class="c"># ...</span>

    <span class="c"># the sitemap</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^sitemap\.xml$&#39;</span><span class="p">,</span> <span class="n">sitemap</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">},</span>
        <span class="n">name</span><span class="o">=</span><span class="s">&#39;django.contrib.sitemaps.views.sitemap&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-sitemap-for-static-views">
<span id="sitemap-for-static-views"></span><h2>Sitemap for static views<a class="headerlink" href="#sitemap-for-static-views" title="Permalink to this headline">¶</a></h2>
<p>Often you want the search engine crawlers to index views which are neither
object detail pages nor flatpages. The solution is to explicitly list URL
names for these views in <tt class="docutils literal"><span class="pre">items</span></tt> and call
<a class="reference internal" href="../urlresolvers.html#django.core.urlresolvers.reverse" title="django.core.urlresolvers.reverse"><tt class="xref py py-func docutils literal"><span class="pre">reverse()</span></tt></a> in the <tt class="docutils literal"><span class="pre">location</span></tt> method of
the sitemap. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># sitemaps.py</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">sitemaps</span>
<span class="kn">from</span> <span class="nn">django.core.urlresolvers</span> <span class="kn">import</span> <span class="n">reverse</span>

<span class="k">class</span> <span class="nc">StaticViewSitemap</span><span class="p">(</span><span class="n">sitemaps</span><span class="o">.</span><span class="n">Sitemap</span><span class="p">):</span>
    <span class="n">priority</span> <span class="o">=</span> <span class="mf">0.5</span>
    <span class="n">changefreq</span> <span class="o">=</span> <span class="s">&#39;daily&#39;</span>

    <span class="k">def</span> <span class="nf">items</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="s">&#39;main&#39;</span><span class="p">,</span> <span class="s">&#39;about&#39;</span><span class="p">,</span> <span class="s">&#39;license&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">location</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">reverse</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

<span class="c"># urls.py</span>
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">url</span>
<span class="kn">from</span> <span class="nn">django.contrib.sitemaps.views</span> <span class="kn">import</span> <span class="n">sitemap</span>

<span class="kn">from</span> <span class="nn">.sitemaps</span> <span class="kn">import</span> <span class="n">StaticViewSitemap</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">views</span>

<span class="n">sitemaps</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;static&#39;</span><span class="p">:</span> <span class="n">StaticViewSitemap</span><span class="p">,</span>
<span class="p">}</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">main</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;main&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^about/$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">about</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;about&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^license/$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">license</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;license&#39;</span><span class="p">),</span>
    <span class="c"># ...</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^sitemap\.xml$&#39;</span><span class="p">,</span> <span class="n">sitemap</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">},</span>
        <span class="n">name</span><span class="o">=</span><span class="s">&#39;django.contrib.sitemaps.views.sitemap&#39;</span><span class="p">)</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-creating-a-sitemap-index">
<span id="creating-a-sitemap-index"></span><h2>Creating a sitemap index<a class="headerlink" href="#creating-a-sitemap-index" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="django.contrib.sitemaps.views.index">
<tt class="descclassname">views.</tt><tt class="descname">index</tt>(<em>request</em>, <em>sitemaps</em>, <em>template_name='sitemap_index.xml'</em>, <em>content_type='application/xml'</em>, <em>sitemap_url_name='django.contrib.sitemaps.views.sitemap'</em>)<a class="headerlink" href="#django.contrib.sitemaps.views.index" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The sitemap framework also has the ability to create a sitemap index that
references individual sitemap files, one per each section defined in your
<tt class="docutils literal"><span class="pre">sitemaps</span></tt> dictionary. The only differences in usage are:</p>
<ul class="simple">
<li>You use two views in your URLconf: <a class="reference internal" href="#django.contrib.sitemaps.views.index" title="django.contrib.sitemaps.views.index"><tt class="xref py py-func docutils literal"><span class="pre">django.contrib.sitemaps.views.index()</span></tt></a>
and <a class="reference internal" href="#django.contrib.sitemaps.views.sitemap" title="django.contrib.sitemaps.views.sitemap"><tt class="xref py py-func docutils literal"><span class="pre">django.contrib.sitemaps.views.sitemap()</span></tt></a>.</li>
<li>The <a class="reference internal" href="#django.contrib.sitemaps.views.sitemap" title="django.contrib.sitemaps.views.sitemap"><tt class="xref py py-func docutils literal"><span class="pre">django.contrib.sitemaps.views.sitemap()</span></tt></a> view should take a
<tt class="docutils literal"><span class="pre">section</span></tt> keyword argument.</li>
</ul>
<p>Here&#8217;s what the relevant URLconf lines would look like for the example above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;django.contrib.sitemaps.views&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^sitemap\.xml$&#39;</span><span class="p">,</span> <span class="s">&#39;index&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">}),</span>
    <span class="p">(</span><span class="s">r&#39;^sitemap-(?P&lt;section&gt;.+)\.xml$&#39;</span><span class="p">,</span> <span class="s">&#39;sitemap&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">}),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>This will automatically generate a <tt class="file docutils literal"><span class="pre">sitemap.xml</span></tt> file that references
both <tt class="file docutils literal"><span class="pre">sitemap-flatpages.xml</span></tt> and <tt class="file docutils literal"><span class="pre">sitemap-blog.xml</span></tt>. The
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> classes and the <tt class="docutils literal"><span class="pre">sitemaps</span></tt>
dict don&#8217;t change at all.</p>
<p>You should create an index file if one of your sitemaps has more than 50,000
URLs. In this case, Django will automatically paginate the sitemap, and the
index will reflect that.</p>
<p>If you&#8217;re not using the vanilla sitemap view &#8211; for example, if it&#8217;s wrapped
with a caching decorator &#8211; you must name your sitemap view and pass
<tt class="docutils literal"><span class="pre">sitemap_url_name</span></tt> to the index view:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.sitemaps</span> <span class="kn">import</span> <span class="n">views</span> <span class="k">as</span> <span class="n">sitemaps_views</span>
<span class="kn">from</span> <span class="nn">django.views.decorators.cache</span> <span class="kn">import</span> <span class="n">cache_page</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^sitemap\.xml$&#39;</span><span class="p">,</span>
        <span class="n">cache_page</span><span class="p">(</span><span class="mi">86400</span><span class="p">)(</span><span class="n">sitemaps_views</span><span class="o">.</span><span class="n">index</span><span class="p">),</span>
        <span class="p">{</span><span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">,</span> <span class="s">&#39;sitemap_url_name&#39;</span><span class="p">:</span> <span class="s">&#39;sitemaps&#39;</span><span class="p">}),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^sitemap-(?P&lt;section&gt;.+)\.xml$&#39;</span><span class="p">,</span>
        <span class="n">cache_page</span><span class="p">(</span><span class="mi">86400</span><span class="p">)(</span><span class="n">sitemaps_views</span><span class="o">.</span><span class="n">sitemap</span><span class="p">),</span>
        <span class="p">{</span><span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">},</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;sitemaps&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-template-customization">
<span id="template-customization"></span><h2>Template customization<a class="headerlink" href="#template-customization" title="Permalink to this headline">¶</a></h2>
<p>If you wish to use a different template for each sitemap or sitemap index
available on your site, you may specify it by passing a <tt class="docutils literal"><span class="pre">template_name</span></tt>
parameter to the <tt class="docutils literal"><span class="pre">sitemap</span></tt> and <tt class="docutils literal"><span class="pre">index</span></tt> views via the URLconf:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;django.contrib.sitemaps.views&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^custom-sitemap\.xml$&#39;</span><span class="p">,</span> <span class="s">&#39;index&#39;</span><span class="p">,</span> <span class="p">{</span>
        <span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">,</span>
        <span class="s">&#39;template_name&#39;</span><span class="p">:</span> <span class="s">&#39;custom_sitemap.html&#39;</span>
    <span class="p">}),</span>
    <span class="p">(</span><span class="s">r&#39;^custom-sitemap-(?P&lt;section&gt;.+)\.xml$&#39;</span><span class="p">,</span> <span class="s">&#39;sitemap&#39;</span><span class="p">,</span> <span class="p">{</span>
        <span class="s">&#39;sitemaps&#39;</span><span class="p">:</span> <span class="n">sitemaps</span><span class="p">,</span>
        <span class="s">&#39;template_name&#39;</span><span class="p">:</span> <span class="s">&#39;custom_sitemap.html&#39;</span>
    <span class="p">}),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>These views return <a class="reference internal" href="../template-response.html#django.template.response.TemplateResponse" title="django.template.response.TemplateResponse"><tt class="xref py py-class docutils literal"><span class="pre">TemplateResponse</span></tt></a>
instances which allow you to easily customize the response data before
rendering. For more details, see the <a class="reference internal" href="../template-response.html"><em>TemplateResponse documentation</em></a>.</p>
<div class="section" id="s-context-variables">
<span id="context-variables"></span><h3>Context variables<a class="headerlink" href="#context-variables" title="Permalink to this headline">¶</a></h3>
<p>When customizing the templates for the
<a class="reference internal" href="#django.contrib.sitemaps.views.index" title="django.contrib.sitemaps.views.index"><tt class="xref py py-func docutils literal"><span class="pre">index()</span></tt></a> and
<a class="reference internal" href="#django.contrib.sitemaps.views.sitemap" title="django.contrib.sitemaps.views.sitemap"><tt class="xref py py-func docutils literal"><span class="pre">sitemap()</span></tt></a> views, you can rely on the
following context variables.</p>
</div>
<div class="section" id="s-index">
<span id="index"></span><h3>Index<a class="headerlink" href="#index" title="Permalink to this headline">¶</a></h3>
<p>The variable <tt class="docutils literal"><span class="pre">sitemaps</span></tt> is a list of absolute URLs to each of the sitemaps.</p>
</div>
<div class="section" id="s-id1">
<span id="id1"></span><h3>Sitemap<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>The variable <tt class="docutils literal"><span class="pre">urlset</span></tt> is a list of URLs that should appear in the
sitemap. Each URL exposes attributes as defined in the
<a class="reference internal" href="#django.contrib.sitemaps.Sitemap" title="django.contrib.sitemaps.Sitemap"><tt class="xref py py-class docutils literal"><span class="pre">Sitemap</span></tt></a> class:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">changefreq</span></tt></li>
<li><tt class="docutils literal"><span class="pre">item</span></tt></li>
<li><tt class="docutils literal"><span class="pre">lastmod</span></tt></li>
<li><tt class="docutils literal"><span class="pre">location</span></tt></li>
<li><tt class="docutils literal"><span class="pre">priority</span></tt></li>
</ul>
<p>The <tt class="docutils literal"><span class="pre">item</span></tt> attribute has been added for each URL to allow more flexible
customization of the templates, such as <a class="reference external" href="https://support.google.com/news/publisher/answer/74288?hl=en">Google news sitemaps</a>. Assuming
Sitemap&#8217;s <a class="reference internal" href="#django.contrib.sitemaps.Sitemap.items" title="django.contrib.sitemaps.Sitemap.items"><tt class="xref py py-attr docutils literal"><span class="pre">items()</span></tt></a> would return a list of items with
<tt class="docutils literal"><span class="pre">publication_data</span></tt> and a <tt class="docutils literal"><span class="pre">tags</span></tt> field something like this would
generate a Google News compatible sitemap:</p>
<div class="highlight-xml+django"><div class="highlight"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="nt">&lt;urlset</span>
  <span class="na">xmlns=</span><span class="s">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span>
  <span class="na">xmlns:news=</span><span class="s">&quot;http://www.google.com/schemas/sitemap-news/0.9&quot;</span><span class="nt">&gt;</span>
<span class="cp">{%</span> <span class="k">spaceless</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">url</span> <span class="k">in</span> <span class="nv">urlset</span> <span class="cp">%}</span>
  <span class="nt">&lt;url&gt;</span>
    <span class="nt">&lt;loc&gt;</span><span class="cp">{{</span> <span class="nv">url.location</span> <span class="cp">}}</span><span class="nt">&lt;/loc&gt;</span>
    <span class="cp">{%</span> <span class="k">if</span> <span class="nv">url.lastmod</span> <span class="cp">%}</span><span class="nt">&lt;lastmod&gt;</span><span class="cp">{{</span> <span class="nv">url.lastmod</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;Y-m-d&quot;</span> <span class="cp">}}</span><span class="nt">&lt;/lastmod&gt;</span><span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">if</span> <span class="nv">url.changefreq</span> <span class="cp">%}</span><span class="nt">&lt;changefreq&gt;</span><span class="cp">{{</span> <span class="nv">url.changefreq</span> <span class="cp">}}</span><span class="nt">&lt;/changefreq&gt;</span><span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">if</span> <span class="nv">url.priority</span> <span class="cp">%}</span><span class="nt">&lt;priority&gt;</span><span class="cp">{{</span> <span class="nv">url.priority</span> <span class="cp">}}</span><span class="nt">&lt;/priority&gt;</span><span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
    <span class="nt">&lt;news:news&gt;</span>
      <span class="cp">{%</span> <span class="k">if</span> <span class="nv">url.item.publication_date</span> <span class="cp">%}</span><span class="nt">&lt;news:publication_date&gt;</span><span class="cp">{{</span> <span class="nv">url.item.publication_date</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;Y-m-d&quot;</span> <span class="cp">}}</span><span class="nt">&lt;/news:publication_date&gt;</span><span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
      <span class="cp">{%</span> <span class="k">if</span> <span class="nv">url.item.tags</span> <span class="cp">%}</span><span class="nt">&lt;news:keywords&gt;</span><span class="cp">{{</span> <span class="nv">url.item.tags</span> <span class="cp">}}</span><span class="nt">&lt;/news:keywords&gt;</span><span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
    <span class="nt">&lt;/news:news&gt;</span>
   <span class="nt">&lt;/url&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endspaceless</span> <span class="cp">%}</span>
<span class="nt">&lt;/urlset&gt;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-pinging-google">
<span id="pinging-google"></span><h2>Pinging Google<a class="headerlink" href="#pinging-google" title="Permalink to this headline">¶</a></h2>
<p>You may want to &#8220;ping&#8221; Google when your sitemap changes, to let it know to
reindex your site. The sitemaps framework provides a function to do just
that: <a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">django.contrib.sitemaps.ping_google()</span></tt></a>.</p>
<dl class="function">
<dt id="django.contrib.sitemaps.ping_google">
<tt class="descname">ping_google</tt>()<a class="reference internal" href="../../_modules/django/contrib/sitemaps.html#ping_google"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.sitemaps.ping_google" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">ping_google()</span></tt></a> takes an optional argument, <tt class="docutils literal"><span class="pre">sitemap_url</span></tt>,
which should be the absolute path to your site&#8217;s sitemap (e.g.,
<tt class="file docutils literal"><span class="pre">'/sitemap.xml'</span></tt>). If this argument isn&#8217;t provided,
<a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">ping_google()</span></tt></a> will attempt to figure out your
sitemap by performing a reverse looking in your URLconf.</p>
<p><a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">ping_google()</span></tt></a> raises the exception
<tt class="docutils literal"><span class="pre">django.contrib.sitemaps.SitemapNotFound</span></tt> if it cannot determine your
sitemap URL.</p>
</dd></dl>

<div class="admonition-register-with-google-first admonition">
<p class="first admonition-title">Register with Google first!</p>
<p class="last">The <a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">ping_google()</span></tt></a> command only works if you have registered your
site with <a class="reference external" href="http://www.google.com/webmasters/tools/">Google Webmaster Tools</a>.</p>
</div>
<p>One useful way to call <a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">ping_google()</span></tt></a> is from a model&#8217;s <tt class="docutils literal"><span class="pre">save()</span></tt>
method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.sitemaps</span> <span class="kn">import</span> <span class="n">ping_google</span>

<span class="k">class</span> <span class="nc">Entry</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="c"># ...</span>
    <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">force_insert</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">force_update</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">Entry</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">force_insert</span><span class="p">,</span> <span class="n">force_update</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">ping_google</span><span class="p">()</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="c"># Bare &#39;except&#39; because we could get a variety</span>
            <span class="c"># of HTTP-related exceptions.</span>
            <span class="k">pass</span>
</pre></div>
</div>
<p>A more efficient solution, however, would be to call <a class="reference internal" href="#django.contrib.sitemaps.ping_google" title="django.contrib.sitemaps.ping_google"><tt class="xref py py-func docutils literal"><span class="pre">ping_google()</span></tt></a> from a
cron script, or some other scheduled task. The function makes an HTTP request
to Google&#8217;s servers, so you may not want to introduce that network overhead
each time you call <tt class="docutils literal"><span class="pre">save()</span></tt>.</p>
<div class="section" id="s-pinging-google-via-manage-py">
<span id="pinging-google-via-manage-py"></span><h3>Pinging Google via <tt class="docutils literal"><span class="pre">manage.py</span></tt><a class="headerlink" href="#pinging-google-via-manage-py" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-ping_google">
<tt class="descname">django-admin.py ping_google</tt><a class="headerlink" href="#django-admin-ping_google" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Once the sitemaps application is added to your project, you may also
ping Google using the <tt class="docutils literal"><span class="pre">ping_google</span></tt> management command:</p>
<div class="highlight-python"><div class="highlight"><pre>python manage.py ping_google [/sitemap.xml]
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The sitemap framework</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#installation">Installation</a></li>
<li><a class="reference internal" href="#initialization">Initialization</a></li>
<li><a class="reference internal" href="#sitemap-classes">Sitemap classes</a></li>
<li><a class="reference internal" href="#a-simple-example">A simple example</a></li>
<li><a class="reference internal" href="#sitemap-class-reference">Sitemap class reference</a></li>
<li><a class="reference internal" href="#shortcuts">Shortcuts</a><ul>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#sitemap-for-static-views">Sitemap for static views</a></li>
<li><a class="reference internal" href="#creating-a-sitemap-index">Creating a sitemap index</a></li>
<li><a class="reference internal" href="#template-customization">Template customization</a><ul>
<li><a class="reference internal" href="#context-variables">Context variables</a></li>
<li><a class="reference internal" href="#index">Index</a></li>
<li><a class="reference internal" href="#id1">Sitemap</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pinging-google">Pinging Google</a><ul>
<li><a class="reference internal" href="#pinging-google-via-manage-py">Pinging Google via <tt class="docutils literal"><span class="pre">manage.py</span></tt></a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="redirects.html">The redirects app</a></li>
    
    
      <li>Next: <a href="sites.html">The &#8220;sites&#8221; framework</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../index.html">API Reference</a>
        
          <ul><li><a href="index.html"><tt class="docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
        <ul><li>The sitemap framework</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/ref/contrib/sitemaps.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="redirects.html" title="The redirects app">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="sites.html" title="The &amp;#8220;sites&amp;#8221; framework">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>